package com.aiinterview.subjectservice.controller;


import com.aiinterview.common.entity.PageResult;
import com.aiinterview.common.entity.Result;
import com.aiinterview.model.subject.dto.SubjetQueryDto;
import com.aiinterview.model.subject.vo.SubjectInfoVo;
import com.aiinterview.subjectservice.service.SubjectInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/subject")
@Slf4j
public class SubjectInfoController {

    @Autowired
    private SubjectInfoService subjectInfoService;

    /**
     * 分页查询题目列表
     * @param subjetQueryDto
     * @return
     */
    @PostMapping("/getsubjetlist")
    public Result<PageResult> getSubjetList(@RequestBody SubjetQueryDto subjetQueryDto){
        log.info("subjetQueryDto:{}", subjetQueryDto);
        PageResult pageQuery = subjectInfoService.pageQuery(subjetQueryDto);
        log.info("分页查询结果pageQuery:{}",pageQuery);
        return Result.ok(pageQuery);
    }

    /**
     * 根据题目ID查询题目信息
     * @param id
     * @return
     */
    @GetMapping("/getInfoById")
    public Result<SubjectInfoVo> getInfoById(@RequestParam("id") Long id){
        log.info("根据题目ID查询题目信息，id:{}",id);
        SubjectInfoVo subjectInfoVo = subjectInfoService.getInfoById(id);
        return Result.ok(subjectInfoVo);
    }

    // 点赞
    @GetMapping("/like")
    public Result like(@RequestParam("subjectId") Long subjectId){
        log.info("题目点赞，题目id:{}",subjectId);
        String msg = subjectInfoService.like(subjectId);
        return Result.ok(msg);
    }

    // 收藏
    @GetMapping("/favorite")
    public Result favorite(@RequestParam("subjectId") Long subjectId){
        log.info("题目收藏，题目id:{}",subjectId);
        String msg = subjectInfoService.favorite(subjectId);
        return Result.ok(msg);
    }

}
